package com.group.controller;

import com.common.domain.dto.GroupAddDTO;
import com.common.domain.dto.GroupUpdateDTO;
import com.common.domain.po.Group;
import com.common.domain.vo.GroupAdminListByPageVO;
import com.common.domain.vo.GroupWebListVO;
import com.common.result.Result;
import com.group.service.GroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 路亚
 * @version 0.1
 * @className GroupController
 * @description
 * @date 2024/12/14 19:24
 * @since jdk11
 */
@RestController
@RequestMapping("/group")
@Slf4j
@Api(tags = "剧单管理")
@RequiredArgsConstructor
public class GroupController {

    private final GroupService groupService;

    @PostMapping("/add")
    @ApiOperation("添加剧单")
    public Result add(@RequestBody GroupAddDTO dto) {
        log.info("添加剧单,添加数据为:{}", dto);
        groupService.add(dto);
        return Result.success();
    }

    @PostMapping("/update")
    @ApiOperation("更新剧单")
    public Result update(@RequestBody GroupUpdateDTO dto) {
        log.info("更新剧单,更新数据为:{}", dto);
        groupService.updateGroup(dto);
        return Result.success();
    }

    @GetMapping("/webList")
    @ApiOperation("分页查询--客户端")
    public Result webList(Integer page){
        log.info("分页查询--客户端,page:{}", page);
        List<GroupWebListVO> result = groupService.webList(page);
        return new Result(200, "OK", result);
    }

    @GetMapping("/adminList")
    @ApiOperation("分页查询--管理端")
    public Result adminList(Integer page){
        log.info("分页查询--管理端,page:{}", page);
        GroupAdminListByPageVO result = groupService.adminList(page);
        return new Result(200, "OK", result);
    }

    @DeleteMapping("/deleteById")
    @ApiOperation("根据id删除剧单")
    public Result deleteById(Long id) {
        log.info("根据id删除剧单,id:{}", id);
        groupService.removeById(id);
        return Result.success();
    }
}
